
package crm.salesOrderProcessing.managedbean;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import crm.salesOrderProcessing.entity.LineItemEntity;
import crm.salesOrderProcessing.entity.SalesInquiryEntity;
import crm.salesOrderProcessing.entity.SalesQuotationEntity;

@ManagedBean
@ViewScoped
public class CreateQuotationResultManagedBean implements Serializable{
    
    private SalesQuotationEntity salesQuotation;
    private List<LineItemEntity> lineItems;
    private Long salesQuotationId;
    private String message; 
    private double userDiscount;
    private double totalPrice;

    /** Creates a new instance of CreateInquiryResultManagedBean */
    public CreateQuotationResultManagedBean() {
    }
    
    public void initView(PhaseEvent event) {
        if (salesQuotation == null) {
            
           salesQuotation = (SalesQuotationEntity) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("newQuotation");
        }
        setLineItems(salesQuotation.getQuotationLineItems());
        setSalesQuotationId(salesQuotation.getId());
        setUserDiscount(salesQuotation.getUserDiscount());
        setTotalPrice(salesQuotation.getTotalPrice());
        message = "Sales Quotation has been saved. ID: "+String.valueOf(salesQuotationId);
     }

    public void editInquiry() throws IOException{
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("quotation", salesQuotation);
        FacesContext.getCurrentInstance().getExternalContext().redirect("editSalesQuotation.xhtml");
    }
    
    public void goBack() throws IOException{
        FacesContext.getCurrentInstance().getExternalContext().redirect("./deleteSalesQuotation.xhtml");
    }
    
    public void goBack2() throws IOException{
        FacesContext.getCurrentInstance().getExternalContext().redirect("./deleteSalesQuotation.xhtml");
    }

    public SalesQuotationEntity getSalesQuotation() {
        return salesQuotation;
    }

    public void setQuotation(SalesQuotationEntity quotaiton) {
        this.salesQuotation = quotaiton;
    }

    public List<LineItemEntity> getLineItems() {
        return lineItems;
    }

    public void setLineItems(List<LineItemEntity> lineItems) {
        this.lineItems = lineItems;
    }

    public Long getSalesQuotationId() {
        return salesQuotationId;
    }

    public void setSalesQuotationId(Long salesQuotationId) {
        this.salesQuotationId = salesQuotationId;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public double getUserDiscount() {
        return userDiscount;
    }

    public void setUserDiscount(double userDiscount) {
        this.userDiscount = userDiscount;
    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    
}
